import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description: 顺序表--第一次作业
 * User: 王圆豪
 * Date: 2024-09-07
 * Time: 0:23
 */
public class Arr {
    int[] data;

    public Arr(int n) {
        this.data = new int[n];
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            int k = random.nextInt(1000);
            this.data[i] = k;
        }
    }

    public void display(){
        for (int datum : data) {
            System.out.print(datum + " ");
        }
        System.out.println();
    }

    public void reverse() {
        for (int i = 0; i < data.length / 2; i++) {
            int temp = data[i];
            data[i] = data[data.length - 1 - i];
            data[data.length - 1 - i] = temp;
        }
        display();
    }

    public void sort() {
        for (int i = 0; i < data.length - 1; i++) {
            for (int j = 0; j < data.length - 1 - i; j++) {
                if (data[j] > data[j + 1]){
                    int tmp = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = tmp;
                }
            }
        }
        display();
    }

    public int search(int k) {
        for (int i = 0; i < data.length; i++) {
            if (data[i] == k) {
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        Arr arr = new Arr(10);
        arr.display();
        arr.reverse();
        arr.sort();
        System.out.println(arr.search(arr.data[8]));
    }
}
